package org.redis.cluster.registry.zookeeper.test;

import java.util.concurrent.TimeUnit;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.leader.LeaderLatch;
import org.apache.curator.retry.RetryForever;

public class ZookeeperRegistryTester_2 {

	public static void main(String[] args) throws Exception {
		for(int i=0;i<10;i++) {
			CuratorFramework client=CuratorFrameworkFactory.builder()
					.retryPolicy(new RetryForever(1000*3))
					.sessionTimeoutMs(1000*1)
					.connectString("127.0.0.1").build();
			client.start();
			
			new Thread(()->{
				LeaderLatch leaderLatch=new LeaderLatch(client,"/test");
				
				try {
					leaderLatch.start();
					leaderLatch.await(1000*50, TimeUnit.MILLISECONDS);
					System.out.println(leaderLatch.hasLeadership());
				}
				catch(Exception e) {
					e.printStackTrace();
				}
			}).start();
			
			System.out.println(i);
		}
		
		System.in.read();
	}
}